//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using OpenLS.Spreadsheet.Extensibility;

namespace OpenLS.Spreadsheet.Extensibility
{
    public class TreatRangeAsEnumerableObjectAttribute: ParameterConverterAttribute
    {
        internal override void ConvertImp(ConversionData data)
        {
            if (data.TargetType == typeof(IEnumerable<object>))
            {
                IRange r = data.Value as IRange;
                if (r != null)
                    data.Result = GetRangeValuesEnumerator(r);
            }
        }

        static IEnumerable<object> GetRangeValuesEnumerator(IRange range)
        {
            foreach (ICell cell in range.GetNonEmptyCells())
                if (cell.Value != null)
                    yield return cell.Value;
        }
    }
}
